<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="../templates/layout.xhtml">

	<ui:define name="content">
		<h:form prependId="false" id="growlForm">
			<p:growl id="growl" showDetail="true" />
		</h:form>
		<h:form id="controlForm" prependId="false">
			<p:panel id="kelurahanPanel">

				<h:panelGrid columns="1" columnClasses="col1">
					<h:outputLabel for="kelurahanInput" value="Kelurahan: " />
					<p:autoComplete binding="#{kelurahanVoteBean.autoComplete}"
						id="kelurahanInput">
						<p:ajax event="itemSelect" listener="#{kelurahanVoteBean.handle}"
							update="chartOutput,@form" />
					</p:autoComplete>
				</h:panelGrid>
				<p:ajaxStatus>
					<f:facet name="start">
						<h:graphicImage library="images" name="ajax-loader.gif"
							alt="loader" />
					</f:facet>
					<f:facet name="complete">
						<p:commandButton id="downloadButton"
							value="Export" action="#{exportTpsBean.display}" ajax="false" async="false">
							<f:setPropertyActionListener target="#{exportTpsBean.kelurahan}" value="#{kelurahanVoteBean.kelurahan}"/>
						</p:commandButton>
					</f:facet>
				</p:ajaxStatus>
				
			</p:panel>
				<p:panel rendered="#{kelurahanVoteBean.dataVisible}" id="chartOutput">
					<f:facet name="header">
						<h:outputText value="#{messages.label_temp_result} #{messages.label_village}" />
					</f:facet>
					<p:dataList value="#{kelurahanVoteBean.voteDescription}" var="desc" rendered="#{kelurahanVoteBean.dataVisible}">
						<h:outputText value="#{desc}" />
					</p:dataList>
					<p:dataTable id="reportTable" value="#{kelurahanVoteBean.voteMaps}"
						var="t" resizableColumns="false" widgetVar="pTable" paginator="true"
						paginatorTemplate=" {CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
					rowsPerPageTemplate="5,10,25,50" rows="10" rendered="#{kelurahanVoteBean.dataVisible}">
						<p:column>
							<f:facet name="header">
								<h:outputText value="Nama TPS" />
							</f:facet>
							<h:outputText value="#{t.areaId}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Update Terakhir" />
							</f:facet>
							<h:outputText value="#{t.lastUpdate}" />
						</p:column>
						<p:columns var="col" columnIndexVar="colIndex"
							value="#{kelurahanVoteBean.columns}">
							<f:facet name="header">
								<h:outputText value="#{col}" />
							</f:facet>
							<h:outputText value="#{t.voteResult.get(col)}"></h:outputText>
						</p:columns>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Total Suara" />
							</f:facet>
							<h:outputText value="#{t.total}" />
						</p:column>
					</p:dataTable>
					<p:barChart value="#{kelurahanVoteBean.model}" legendPosition="ne"
						enhancedLegend="true" barMargin="20" barPadding="21" rendered="#{kelurahanVoteBean.dataVisible}"/>
				
				</p:panel>
			
		</h:form>
		<p:dialog id="downloadDialog" header="Download" 
			modal="true" widgetVar="downloadDialog" 
			dynamic="true" resizable="true" maximizable="true" showEffect="fade" hideEffect="fade">
     	 <p:outputPanel id="downloadPanel">
        	<h:form id="downloadForm">
         		 <h:panelGrid columns="2" columnClasses="col1,col2" id="downloadGrid">
					<h:outputText value="Ekspor Data untuk Kelurahan: #{exportTpsBean.kelurahan.name}" />
				</h:panelGrid>
         		 <h:panelGrid columns="2" columnClasses="col1,col2">
         		  <p:commandButton id="downloadButton" value="Download" ajax="false" async="false">
         		  	<p:fileDownload value="#{exportTpsBean.content}"/>
         		  </p:commandButton>
         		 <p:commandButton id="downloadCloseButton" value="#{messages.label_close}" onclick="downloadDialog.hide()" type="button" action="#{exportTpsBean.clear}" update="downloadPanelGrid"/>
         		 </h:panelGrid>
       		 </h:form>
      </p:outputPanel>
      </p:dialog>

	</ui:define>
</ui:composition>
</html>